/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
var combinationSum = function(candidates, target) {
  let ans = []
  let path = []
  /**
   * 
   * @param {*} index 当前索引
   * @param {*} numsLeft 剩下的数
   */
  const dfs = (index, numsLeft) => {
    if(index >= candidates.length || numsLeft < 0) return
    if(numsLeft.length === 0) {
      ans.push(path.concat()) // 找到答案
      return
    }
    for(let i = index; i < candidates.length; i++) {
      path.push(candidates[i])
      dfs(i, numsLeft - candidates[i])
      path.pop()
    }
  }
  dfs(0, target)
  return ans
};